package com.example.threadpool2.controller;

import com.example.threadpool2.service.ThreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 多线程控制类
 *
 * @author zhuyonggang
 * @DateTime: 2021/8/30 15:23
 */
@RestController
@RequestMapping("api/thread")
public class ThreadController {
    @Autowired
    private ThreadService threadService;

    @PostMapping("/sync")
    public void sync() {
        this.threadService.sync();
    }

    public static void sleep(){
        try {
            Thread.sleep(1000);
            System.out.println("Thread:"+Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
